package kit.main;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import kit.persistency.KitDB;

public class MainE {
/*
	public static void main(String[] args) throws IOException {
		deleteTempDB("temp.db");
		
		FileReader fr = new FileReader(new File("surname-occ-entropy.txt"));
		BufferedReader bfr = new BufferedReader(fr);

		createTempDB("temp.db");
		KitDB tempDB = new KitDB();
		String line;
		LinkedList<String> maccos =  new LinkedList<>();
		while ((line = bfr.readLine()) != null) {
			String[] splittedLine = line.split(";");

			String cognome = splittedLine[0];
			int frequenza = Integer.parseInt(splittedLine[1]);
			double entropia = Double.parseDouble(splittedLine[2]);
			
			if(!tempDB.insertDomainElement(cognome, frequenza))
				System.err.println("!!!");
			maccos.add(cognome+" "+entropia);			
		}
		int i = 0;
		String[] amacco = maccos.toArray(new String[0]);
		Arrays.sort(amacco);
		for(String cognome : tempDB.getDomainElements()){
			System.out.println(amacco[i]);
			System.out.println(cognome+" "+tempDB.calculateOriginalEntropy(cognome));
			if(!amacco[i].equals(cognome+" "+tempDB.calculateOriginalEntropy(cognome))){
				System.err.println("Valori differenti!");
				System.exit(1);
			}
			i++;
		}
		System.err.println("Ok!");
		bfr.close();
	}

	private static void createTempDB(String dbName) throws IOException {
		KitDB db = null;
		if (!new File( dbName).exists()) {
			File fileDB = new File(dbName);
			fileDB.createNewFile();
			db = new KitDB(fileDB.getAbsolutePath());
			try {
				db.dbDDL();
			} catch (SQLException e) {
				fileDB.delete();
				System.exit(1);
			}
		}
	}
	
	private static void deleteTempDB(String dbName){
		File fileDB = new File(dbName);
		if(fileDB.exists())
			fileDB.delete();
	}
	*/
}
